//
//  VRankCollectionViewCell.m
//  CapriceMusic
//
//  Created by 蒋恩浩 on 16/1/13.
//  Copyright © 2016年 MYX. All rights reserved.
//

#import "VRankCollectionViewCell.h"

@interface VRankCollectionViewCell ()

@property (nonatomic, strong) UIImageView *picture;
@property (nonatomic, strong) JEHLabel *rankLabel;
@property (nonatomic, strong) JEHLabel *scoreLabel;
@property (nonatomic, strong) JEHLabel *titleLabel;
@property (nonatomic, strong) JEHLabel *nameLabel;

@end

@implementation VRankCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.picture = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.picture.alpha = 0.8;
        self.rankLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:25 withTextColor:[UIColor whiteColor]];
        self.scoreLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:18 withTextColor:[UIColor whiteColor]];
        self.trendLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:16 withTextColor:[UIColor whiteColor]];
        self.titleLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:16 withTextColor:[UIColor whiteColor]];
        self.titleLabel.textAlignment = NSTextAlignmentRight;
        self.nameLabel = [[JEHLabel alloc] initWithFrame:CGRectZero withFont:16 withTextColor:[UIColor colorWithRed:30 / 255.0 green:195 / 255.0 blue:153 / 255.0 alpha:1.0]];
        self.nameLabel.textAlignment = NSTextAlignmentRight;
        [self addSubview:self.picture];
        [self addSubview:self.rankLabel];
        [self addSubview:self.scoreLabel];
        [self addSubview:self.trendLabel];
        [self addSubview:self.titleLabel];
        [self addSubview:self.nameLabel];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    
    self.picture.frame = self.bounds;
    self.rankLabel.frame = CGRectMake(20, self.height - 50, 50, 25);
    self.scoreLabel.frame = CGRectMake(20, self.height - 25, 60, 20);
    self.trendLabel.frame = CGRectMake(20 + 60, self.height - 25, 60 + 10, 20);
    self.titleLabel.frame = CGRectMake(self.width / 2, self.height - 40, self.width / 2 - 10, 20);
    self.nameLabel.frame = CGRectMake(self.width / 2, self.height - 20, self.width / 2 - 10, 20);
}

- (void)setVRankModel:(VRankModel *)vRankModel {
    
    if (_vRankModel != vRankModel) {
        
        _vRankModel = vRankModel;
    }
    [self.picture sd_setImageWithURL:[NSURL URLWithString:vRankModel.albumImg]];
    self.scoreLabel.text = vRankModel.score;
    if (vRankModel.up == true) {
        
        self.trendLabel.text = [NSString stringWithFormat:@"⬆︎%@", vRankModel.trendScore];
        self.trendLabel.textColor = [UIColor redColor];
    } else {
        self.trendLabel.text = [NSString stringWithFormat:@"⬇︎%@", vRankModel.trendScore];
        self.trendLabel.textColor = [UIColor colorWithRed:30 / 255.0 green:195 / 255.0 blue:153 / 255.0 alpha:1.0];
    }
    self.titleLabel.text = vRankModel.title;
    self.nameLabel.text = vRankModel.artistName;
}

- (void)setCount:(NSInteger)count {
    
    if (_count != count) {
        
        _count = count;
    }
    self.rankLabel.text = [NSString stringWithFormat:@"%ld", count];
}

@end



















